package com.mdxq.springboot04_mybatis_plus.controller;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdxq.springboot04_mybatis_plus.entity.Manager;
import com.mdxq.springboot04_mybatis_plus.service.ManagerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class ManagerController {
    @Resource
    private ManagerService managerService;

    @GetMapping("/manager/queryAll")
    public List<Manager> queryAll() {
        return managerService.list();
    }

    @GetMapping("/manager/queryByCondition")
    public List<Manager> queryByCondition(@RequestBody Manager manager) {
        //managerService.list();没有添加参数，则返回整个Manager表集合。
        //List<Manager> list = managerService.list();
        //该类型是mybatis-plus封装的条件对象。
        //Wrapper是抽象类，我们实际上在查询的时候使用的是该类的子类：QueryWrapper
        QueryWrapper<Manager> queryWrapper = new QueryWrapper<>();
        boolean username = false;
        queryWrapper.eq(!username,"username","admin");
        //如果添加参数，则参数只能是Wrapper类型的对象。
        List<Manager> list = managerService.list(queryWrapper);
        return list;
    }




}